/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Client;

import Communication.S2ClientPacket;
import java.io.ObjectInputStream;


/**
 *
 * @author cypek
 */
public class ClientListner implements Runnable {
    
    private ClientController clientController;

    public ClientListner(ClientController clientController) {
        this.clientController = clientController;
    }

    private S2ClientPacket inpacket;

    public S2ClientPacket getInpacket() {
        return inpacket;
    }

    public void setInpacket(S2ClientPacket inpacket) {
        this.inpacket = inpacket;
    }


/**
 *
 * @author cypek
 */
    public void run()
    {
        try {
                while(clientController.getClient().isClientRunning())
                {
                        ObjectInputStream ois = new ObjectInputStream(this.clientController.getSocket().getInputStream());
                        Object readObject = ois.readObject();

                    if ( readObject instanceof S2ClientPacket ){
                        inpacket = (S2ClientPacket)readObject;
                        //System.out.println("Current Lift Floor : " + inpacket.getCurrentFloor());
                        //System.out.println("Client Current State : " + inpacket.getCurrentState());
                        this.clientController.getClient().setCurrentFloor(inpacket.getCurrentFloor());
                        this.clientController.getClient().setState(inpacket.getCurrentState());             
                    }
                }
        }
           catch (Exception ex) {
                  //to do
               System.out.println("Blad podczas nasluchiwania");
          }
    }
}
